﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Net.Mail;
using System.Net;

namespace NormReference.Services
{
    public class EmailWriter
    {
        public static EmailWriter instance;

        private EmailWriter()
        {
 
        }

        public static EmailWriter getInstance()
        {
            if (instance == null)
            {
                instance = new EmailWriter();
            }

            return instance;
        }

        public void SendMessage(string toEmail, string subject, string body)
        {
            Logger.getInstance().printToLogFile("In send message method of the EmailWriter.");
            MailAddress toAddress = new MailAddress(toEmail);
            MailAddress fromAddress = new MailAddress("kylehaw@gmail.com");
            string fromPassword = "k1haw6kins";

            SmtpClient smtp = new SmtpClient
                {
                    Host = "smtp.gmail.com",
                    Port = 587,
                    EnableSsl = true,
                    DeliveryMethod = SmtpDeliveryMethod.Network,
                    UseDefaultCredentials = false,
                    Credentials = new NetworkCredential(fromAddress.Address, fromPassword)

                };

            MailMessage message = new MailMessage(fromAddress, toAddress)
                {
                    Subject = subject,
                    Body = body
                };


            smtp.Send(message);
        }
    }

    
}